package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.search.AlbumInfoIndex;
import com.atguigu.tingshu.query.album.AlbumInfoQuery;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import com.mysql.cj.x.protobuf.MysqlxCursor;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"all"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;
    /**
     * @author WeakMoon
     * @date 2025/03/05 16:14:55
     * 获取排行榜
     */
    @Operation(summary = "获取排行榜")
    @GetMapping("/findRankingList/{category1Id}/{ranking}")
    public Result findRankingList(@PathVariable Long category1Id,@PathVariable String ranking){
        //调用服务层方法
        List<AlbumInfoIndex> list = searchService.findRankingList(category1Id,ranking);

        //返回结果数据
        return Result.ok(list);
    }

    /**
     * @author WeakMoon
     * @date 2025/03/04 21:38:43
     * 更新排行榜
     */
    @Operation(summary = "更新排行榜")
    @GetMapping("updateLatelyAlbumRanking")
    public Result updateLatelyAlbumRanking(){
        //调用服务层方法
        searchService.updateLatelyAlbumRanking();

        //返回结果数据
        return Result.ok();
    }

    /**
     * @author WeakMoon
     * @date 2025/02/28 19:04:56
     * 自动补全
     * 接口地址：http://localhost/api/search/albumInfo/completeSuggest/SSD
     * 请求方式：get
     */
    @Operation(summary = "自动补全")
    @GetMapping("/completeSuggest/{keyword}")
    public Result completeSuggest(@PathVariable String keyword){
        //调用服务层方法
        List<String> list = searchService.completeSuggest(keyword);
        //返回数据结果
        return Result.ok(list);
    }

    /**
     * @author WeakMoon
     * @date 2025/02/28 16:18:35
     * 展示频道页数据
     * 接口地址：http://localhost/api/search/albumInfo/channel/1
     * 请求方式：get
     */
    @Operation(summary = "展示频道页数据")
    @GetMapping("/channel/{category1Id}")
    public Result channel(@PathVariable Long category1Id){
        //调用服务处方法
        List<Map<String,Object>> list = searchService.channel(category1Id);
        //返回结果数据
        return Result.ok(list);
    }
    /**
     * @author WeakMoon
     * @date 2025/02/26 20:49:55
     * 检索功能
     * 接口地址：http://localhost/api/search/albumInfo
     * 请求方式：post
     */
    @Operation(summary = "检索")
    @PostMapping
    public Result search(@RequestBody AlbumIndexQuery albumIndexQuery){
        //调用服务层方法
        AlbumSearchResponseVo albumSearchResponseVo = searchService.search(albumIndexQuery);

        //返回结果数据
        return Result.ok(albumSearchResponseVo);
    }

    /**
     * @author WeakMoon
     * @date 2025/02/25 18:48:17
     * 专辑上架
     */
    @Operation(summary = "专辑上架")
    @GetMapping("/upperAlbum/{albumId}")
    public Result upperAlbum(@PathVariable Long albumId){
        //调用服务层方法
        searchService.upperAlbum(albumId);

        //返回结果数据
        return Result.ok();
    }

    /**
     * @author WeakMoon
     * @date 2025/02/25 18:54:40
     * 专辑下架
     */
    @Operation(summary = "专辑下架")
    @GetMapping("/lowerAlbum/{albumId}")
    public Result lowerAlbum(@PathVariable Long albumId){
        //调用服务层方法
        searchService.lowerAlbum(albumId);

        //返回结果数据
        return Result.ok();
    }

    /**
     * @author WeakMoon
     * @date 2025/02/26 15:49:30
     * 批量上架
     */
    @Operation(summary = "批量上架")
    @GetMapping("batchUpperAlbum")
    public Result batchUpperAlbum(){
        // 遍历1到1500的专辑ID，调用上架方法
        for (long i = 1; i <= 1500; i++) {
            searchService.upperAlbum(i);
        }

        // 返回结果数据
        return Result.ok();
    }
}

